#include "logindialog.h"
#include "ui_logindialog.h"

#include <QMessageBox>

LoginDialog::LoginDialog(QWidget* parent)
    : QDialog(parent), ui(new Ui::LoginDialog) {
    ui->setupUi(this);
}

LoginDialog::~LoginDialog() {
    delete ui;
}

void LoginDialog::on_loginButton_clicked() {
    // 判断用户名和密码是否正确,
    // 如果错误则弹出警告对话框
    if (ui->userLineEdit->text().trimmed() == tr("tengyft") &&
        ui->passwordLineEdit->text() == tr("123456")) {
        accept();
    } else {
        QMessageBox::warning(this, tr("警告！"), tr("用户名或密码错误！"),
                             QMessageBox::Yes);
        // 清空内容并定位光标
        ui->userLineEdit->clear();
        ui->passwordLineEdit->clear();
        ui->userLineEdit->setFocus();
    }
}
